<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会话测试</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        button {
            padding: 10px 15px;
            margin: 5px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        pre {
            background-color: #f5f5f5;
            padding: 10px;
            border-radius: 4px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>会话测试工具</h1>
    
    <div>
        <h2>登录测试</h2>
        <input id="userAccount" placeholder="用户账号" value="2023302141060" />
        <input id="userPassword" type="password" placeholder="密码" value="Aa12345678" />
        <button onclick="login()">登录</button>
    </div>
    
    <div>
        <h2>会话测试</h2>
        <button onclick="getCurrentUser()">获取当前用户</button>
        <button onclick="checkCookies()">检查Cookie</button>
    </div>
    
    <div>
        <h2>结果</h2>
        <pre id="result">结果将显示在这里...</pre>
    </div>
    
    <script>
        // 创建axios实例
        const api = axios.create({
            baseURL: 'http://47.109.146.201:6100/api',
            withCredentials: true,
            timeout: 10000
        });
        
        // 显示结果
        function showResult(data) {
            document.getElementById('result').textContent = 
                typeof data === 'object' ? JSON.stringify(data, null, 2) : data;
        }
        
        // 登录
        async function login() {
            try {
                const userAccount = document.getElementById('userAccount').value;
                const userPassword = document.getElementById('userPassword').value;
                
                showResult(`正在登录: ${userAccount}...`);
                
                const response = await api.post('/user/login', {
                    userAccount,
                    userPassword
                });
                
                showResult({
                    response: response.data,
                    cookies: document.cookie
                });
            } catch (error) {
                showResult(`登录错误: ${error.message}`);
            }
        }
        
        // 获取当前用户
        async function getCurrentUser() {
            try {
                showResult('正在获取当前用户...');
                
                const response = await api.get('/user/current');
                
                showResult({
                    response: response.data,
                    cookies: document.cookie
                });
            } catch (error) {
                showResult(`获取用户错误: ${error.message || error}`);
            }
        }
        
        // 检查Cookie
        function checkCookies() {
            showResult({
                cookies: document.cookie,
                cookiesArray: document.cookie.split(';').map(c => c.trim())
            });
        }
    </script>
</body>
</html> 